import com.jfoenix.controls.JFXButton
import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.JFXDrawer.DrawerDirection
import com.jfoenix.controls.JFXDrawersStack
import javafx.application.Application
import javafx.collections.ObservableList
import javafx.scene.Scene
import javafx.scene.input.MouseEvent
import javafx.scene.layout.FlowPane
import javafx.scene.layout.HBox
import javafx.scene.layout.StackPane
import javafx.stage.Stage

import javafx.scene.input.MouseEvent.MOUSE_PRESSED

class DrawerDemo : Application() {

    override fun start(stage: Stage) {
        val content = FlowPane()
        val leftButton = JFXButton(LEFT)
        val topButton = JFXButton(TOP)
        val rightButton = JFXButton(RIGHT)
        val bottomButton = JFXButton(BOTTOM)
        content.children.addAll(leftButton, topButton, rightButton, bottomButton)
        content.setMaxSize(200.0, 200.0)


        val leftDrawer = JFXDrawer()
        val leftDrawerPane = StackPane()
        leftDrawerPane.styleClass.add("red-400")
        leftDrawerPane.children.add(JFXButton("Left Content"))
        val leftPane = HBox()
        leftPane.isFillHeight = true
        leftDrawerPane.children.add(leftPane)
        leftDrawer.setSidePane(leftDrawerPane)
        leftDrawer.defaultDrawerSize = 150.0
        //        leftDrawer.setResizeContent(true);
        leftDrawer.isOverLayVisible = false
        leftDrawer.isResizableOnDrag = true


        val bottomDrawer = JFXDrawer()
        val bottomDrawerPane = StackPane()
        bottomDrawerPane.styleClass.add("deep-purple-400")
        bottomDrawerPane.children.add(JFXButton("Bottom Content"))
        bottomDrawer.defaultDrawerSize = 150.0
        bottomDrawer.direction = DrawerDirection.BOTTOM
        bottomDrawer.setSidePane(bottomDrawerPane)
        //        bottomDrawer.setResizeContent(true);
        bottomDrawer.isOverLayVisible = false
        bottomDrawer.isResizableOnDrag = true


        val rightDrawer = JFXDrawer()
        val rightDrawerPane = StackPane()
        rightDrawerPane.styleClass.add("blue-400")
        rightDrawerPane.children.add(JFXButton("Right Content"))
        rightDrawer.direction = DrawerDirection.RIGHT
        rightDrawer.defaultDrawerSize = 150.0
        rightDrawer.setSidePane(rightDrawerPane)
        rightDrawer.isOverLayVisible = false
        rightDrawer.isResizableOnDrag = true


        val topDrawer = JFXDrawer()
        val topDrawerPane = StackPane()
        topDrawerPane.styleClass.add("green-400")
        topDrawerPane.children.add(JFXButton("Top Content"))
        topDrawer.direction = DrawerDirection.TOP
        topDrawer.defaultDrawerSize = 150.0
        topDrawer.setSidePane(topDrawerPane)
        topDrawer.isOverLayVisible = false
        topDrawer.isResizableOnDrag = true


        val drawersStack = JFXDrawersStack()
        drawersStack.content = content

        leftDrawer.id = LEFT
        rightDrawer.id = RIGHT
        bottomDrawer.id = BOTTOM
        topDrawer.id = TOP

        leftButton.addEventHandler<MouseEvent>(MOUSE_PRESSED) { drawersStack.toggle(leftDrawer) }
        bottomButton.addEventHandler<MouseEvent>(MOUSE_PRESSED) { drawersStack.toggle(bottomDrawer) }
        rightButton.addEventHandler<MouseEvent>(MOUSE_PRESSED) { drawersStack.toggle(rightDrawer) }
        topButton.addEventHandler<MouseEvent>(MOUSE_PRESSED) { drawersStack.toggle(topDrawer) }


        val scene = Scene(drawersStack, 800.0, 800.0)
        val stylesheets = scene.stylesheets
        stylesheets.addAll(DrawerDemo::class.java.getResource("/css/jfoenix-components.css").toExternalForm(),
                DrawerDemo::class.java.getResource("/css/jfoenix-design.css").toExternalForm())

        stage.title = "JFX Drawer Demo"
        stage.scene = scene
        stage.isResizable = true
        stage.show()
    }

    companion object {

        private val LEFT = "LEFT"
        private val TOP = "TOP"
        private val RIGHT = "RIGHT"
        private val BOTTOM = "BOTTOM"

        @JvmStatic
        fun main(args: Array<String>) {
            Application.launch()
        }
    }

}
